package com.genokon.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.genokon.dict.OrderStatus;
import com.genokon.service.OrderVarService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author by baichaoda
 * @date 2021/3/15 14:05
 */
@RestController
@RequestMapping("/ServiceVar")
public class ServiceVariationController {
    @Resource
    private OrderVarService orderVarService;

    @PostMapping("/saveVar")
    public R<String> save(String varData){
        R<String> result;
        try {
            result = R.ok(orderVarService.saveVar(varData));
        } catch (Exception e) {
            result = R.failed(e.getMessage());
        }
        return result;
    }

    @PostMapping("/uploadSample")
    public R<String> uploadSample(String sampleNo){
        R<String> result;
        try {
            result = R.ok(orderVarService.changeOrderStatus(sampleNo, OrderStatus.phyAnalysis.getCode()));
        } catch (Exception e) {
            result = R.failed(e.getMessage());
        }
        return result;
    }

    @PostMapping("/analysisSample")
    public R<String> analysisSample(String sampleNo){
        R<String> result;
        try {
            result = R.ok(orderVarService.changeOrderStatus(sampleNo, OrderStatus.analysisComplete.getCode()));
        } catch (Exception e) {
            result = R.failed(e.getMessage());
        }
        return result;
    }
}
